package com.stellar.circle.domain.sPostTagMapping.impl;

import com.stellar.circle.basic.entity.SPostTagMapping;
import com.stellar.circle.basic.service.SPostTagMappingService;
import com.stellar.circle.controller.admin.sPostTagMapping.vo.SPostTagMappingRequestPageVO;
import com.stellar.circle.controller.admin.sPostTagMapping.vo.SPostTagMappingRequestVO;
import com.stellar.circle.controller.admin.sPostTagMapping.vo.SPostTagMappingResponseVO;
import com.stellar.circle.convert.SPostTagMappingConvert;
import com.stellar.circle.domain.sPostTagMapping.SPostTagMappingDomainService;

import com.stellar.web.core.bean.PageResult;
import com.stellar.web.core.enums.IsDeletedFlagEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 帖子话题关联表领域服务实现
 *
 * @author Jqchan
 * @version 1.0
 * @date 2025-05-17 19:30:49
 */
@Service
public class SPostTagMappingDomainServiceImpl implements SPostTagMappingDomainService {

    @Resource
    private SPostTagMappingService sPostTagMappingService;

    @Override
    public PageResult<SPostTagMappingResponseVO> page(SPostTagMappingRequestPageVO requestPageVO) {
        PageResult<SPostTagMappingResponseVO> pageResult = new PageResult<>();
        SPostTagMapping queryEntity = SPostTagMappingConvert.INSTANCE.convert(requestPageVO);
        queryEntity.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getVal());

        List<SPostTagMapping> entities = sPostTagMappingService.page(queryEntity,
                requestPageVO.getStart(), requestPageVO.getPageSize());

        if (entities.isEmpty()) {
            return pageResult;
        }

        Long count = sPostTagMappingService.count(queryEntity);
        List<SPostTagMappingResponseVO> vos = SPostTagMappingConvert.INSTANCE.convertEntityToRespList(entities);

        pageResult.setResult(vos);
        pageResult.setTotal(count.intValue());
        return pageResult;
    }

    @Override
    public Boolean update(SPostTagMappingRequestVO requestVO) {
        SPostTagMapping entity = SPostTagMappingConvert.INSTANCE.convert(requestVO);
        return sPostTagMappingService.update(entity) != 0;
    }

    @Override
    public Boolean delete(Long id) {
        SPostTagMapping entity = new SPostTagMapping();
        entity.setId(id);
        entity.setIsDeleted(IsDeletedFlagEnum.DELETED.getVal());
        return sPostTagMappingService.update(entity) != 0;
    }

    @Override
    public Boolean insert(SPostTagMappingRequestVO requestVO) {
        SPostTagMapping entity = SPostTagMappingConvert.INSTANCE.convert(requestVO);
        return sPostTagMappingService.insert(entity) != 0;
    }

    @Override
    public SPostTagMappingResponseVO get(Long id) {
        SPostTagMapping entity = sPostTagMappingService.queryById(id);
        return SPostTagMappingConvert.INSTANCE.convert(entity);
    }
}
